package com.itbaizhan.controller;

import com.itbaizhan.service.TOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author spf
 * @date 2024/4/25
 * @time 13:56
 */
@RestController
@RequestMapping("/order")
public class OrdeController {

    @Autowired
    private TOrderService tOrderService;

    @GetMapping("/create")
    public String createOrder(@RequestParam("id") Integer productId, @RequestParam("count") Long count){
        return tOrderService.createOrder(productId, count);
    }

    @GetMapping("/create1")
    public String createOrder1(@RequestParam("id") Integer productId, @RequestParam("count") Long count){
        return tOrderService.createOrderPessimisticlock(productId, count);
    }

    @GetMapping("/create2")
    public String createOrder2(@RequestParam("id") Integer productId, @RequestParam("count") Long count){
        return tOrderService.createOrderOptimisticlock(productId, count);
    }

    @GetMapping("/create3")
    public String createOrder3(@RequestParam("id") Integer productId, @RequestParam("count") Long count){
        return tOrderService.createOrderRedislock(productId, count);
    }

    @GetMapping("/create4")
    public String createOrder4(@RequestParam("id") Integer productId, @RequestParam("count") Long count) throws InterruptedException {
        return tOrderService.createOrderRedissionlock(productId, count);
    }

    @GetMapping("/create5")
    public String createOrder5(@RequestParam("id") Integer productId, @RequestParam("count") Long count) throws Exception {
        return tOrderService.createOrderZklock(productId, count);
    }

}
